package cn.ajb.filemanager.service;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import cn.ajb.filemanager.dao.FileManagerDao;
import cn.ajb.filemanager.dao.SysParamDictDao;
import cn.ajb.filemanager.dao.UserDao;
import cn.ajb.filemanager.entity.FileManager;
import cn.ajb.filemanager.entity.Image;
import cn.ajb.filemanager.entity.SysParamDict;
import cn.ajb.filemanager.entity.User;
import cn.ajb.filemanager.util.FileUtil;
import cn.ajb.filemanager.util.JSONResult;
import cn.ajb.filemanager.util.PageModel;
import cn.ajb.filemanager.util.ZIPUtil;
import cn.ajb.filemanager.vo.TreeViewVo;



@Service
@Transactional
public class FileManagerService {
	private static final Logger logger = Logger.getLogger(FileManagerService.class);
	@Autowired
	private FileManagerDao fileManagerDao ;
	@Autowired
	private SysParamDictDao sysParamDictDao ;
	@Autowired
	private UserDao userDao;
	@Autowired
	private QRService qrService ;
	/**
	 * 通过文件id获取文件本身，及其所有的父级
	 * @param id
	 * @return 返回一个list,装其自身及其所有的父级
	 */
	@Transactional(readOnly=true)
	public List<FileManager> selectFileManagerListById(List<FileManager> list ,Integer id){
		FileManager filemanager = selectFileManagerById(id);
		if (filemanager!=null) {
			list.add(filemanager);
			Integer parentId = filemanager.getParentId();
			if(parentId!=null && parentId>0){
				selectFileManagerListById(list ,parentId);
			}
		}
		return list ;
	}
	@Transactional(readOnly=true)
	private FileManager selectFileManagerById(Integer id){
		return fileManagerDao.selectFileManagerById(id);
	}
	
	
	/**
	 * 通过父级id,查找其底下所有的子集并分页
	 * @param parentId
	 * @return
	 * @throws Exception
	 */
	@Transactional(readOnly=true)
	public PageModel<FileManager> selectFileManagerListByParentIdAndPage(Map<String, Object> paramMap,int pageNo ,int pageSize,HttpServletRequest request ) throws Exception{
		
		paramMap.put("startRow", (pageNo-1)*pageSize);
		paramMap.put("pageSize", pageSize);
		
		List<FileManager> list = fileManagerDao.selectFileManagerListByParentIdAndPage(paramMap);
		//为其查找到的所有文件添加QR码图片路径
		for(FileManager filemanger:list){
			String parentFolderPath="";
			String parentStrCn=filemanger.getParentStrCn();
			if(parentStrCn!=null && !"".equals(parentStrCn)){
				 parentFolderPath = parentStrCn.replace(" -> ", "/");
			}
			String fileName=filemanger.getFileName();
			String folderPath="";
			String imagePath="";
			Image image=null;
			if(filemanger.getFileType()==1 ){
				/*//其为文件夹 文件夹有QR码
				//说明是文件文件则放在其相关父级目录下
				 folderPath = request.getSession().getServletContext().getRealPath("/"+parentFolderPath);
				 //去除后缀名
				 int indexOf = fileName.indexOf(".");
				 fileName=fileName.substring(0,indexOf);
				 imagePath=folderPath+"code.jpg";*/
			}else{
				//其为文件夹
				 folderPath =parentFolderPath+"/"+fileName+"";
				 imagePath=folderPath+"/code.jpg";
				  image=new Image(imagePath);
			}
			filemanger.setImagePath(image);
		}
		
		int totalRecords = fileManagerDao.selectFileManagerListCountByParentId(paramMap);
		PageModel<FileManager> pageModel = new PageModel<FileManager>();
		pageModel.setList(list);
		pageModel.setPageNo(pageNo);
		pageModel.setPageSize(pageSize);
		pageModel.setTotalRecords(totalRecords);
		return pageModel;
	}
	/**
	 * 通过父级id,查找其底下所有的子集
	 * @param parentId
	 * @return
	 * @throws Exception
	 */
	@Transactional(readOnly=true)
	public List<FileManager> selectFileManagerListByParentId(Integer parentId,HttpServletRequest request) throws Exception{
		List<FileManager> fileManagerList = fileManagerDao.selectFileManagerListByParentId(parentId);
		//为其查找到的所有文件添加QR码图片路径
		for(FileManager filemanger:fileManagerList){
			String parentFolderPath="";
			String parentStrCn=filemanger.getParentStrCn();
			if(parentStrCn!=null && !"".equals(parentStrCn)){
				 parentFolderPath = parentStrCn.replace(" -> ", "/");
			}
			String fileName=filemanger.getFileName();
			String folderPath="";
			String imagePath="";
			Image image=null;
			if(filemanger.getFileType()==1 ){
				/*//其为文件夹 文件夹有QR码
				//说明是文件文件则放在其相关父级目录下
				 folderPath = request.getSession().getServletContext().getRealPath("/"+parentFolderPath);
				 //去除后缀名
				 int indexOf = fileName.indexOf(".");
				 fileName=fileName.substring(0,indexOf);
				 imagePath=folderPath+fileName+".jpg";*/
			}else{
				//其为文件夹
				
				 folderPath =parentFolderPath+"/"+fileName+"";
				 imagePath=folderPath+"/code.jpg";
				  image=new Image(imagePath);
			}
			filemanger.setImagePath(image);
		}
		return fileManagerList;
	}
	/**
	 * 文件上传
	 * @param fileUpload
	 * @param parentId
	 * @param parentStrCn
	 * @param level
	 * @throws IOException
	 */
	public JSONResult<String> fileUpload(
			CommonsMultipartFile fileUpload,Integer parentId,String parentStrCn,Integer level,HttpServletRequest request,
			String sysType,String productName,String productType,String productModel,
			String usageScenarios,String documentType,String version,String materiel,String uploadUser ,String specialNum
			) throws IllegalStateException, IOException{
		JSONResult<String> jsonResult = new JSONResult<String>();
		String fileName = fileUpload.getOriginalFilename();
		FileManager fileManagerInDataBase = fileManagerDao.selectFileManagerByCondition(new FileManager(parentId,fileName,1));
		if(fileManagerInDataBase!=null && fileManagerInDataBase.getId()>1){
			jsonResult.setStatus(JSONResult.STATUS_FAILED);
			jsonResult.setMsg("上传文件失败，因为该文件在该文件夹下已存在!");
		}else{
			FileManager fileManager = new FileManager();
			fileManager.setParentId(parentId);
			fileManager.setFileName(fileName);
			fileManager.setParentStrCn(parentStrCn);
			fileManager.setLevel(level);
			fileManager.setFileType(1);
			fileManager.setDownloadCount(0);
			fileManager.setFileSize((double)fileUpload.getFileItem().getSize()/1024);
			fileManager.setCreateDate(new Date());
			fileManager.setUpdateDate(new Date());
			fileManager.setSysType(sysType);
			fileManager.setProductName(productName);
			fileManager.setProductType(productType);
			fileManager.setProductModel(productModel);
			fileManager.setUsageScenarios(usageScenarios);
			fileManager.setDocumentType(documentType);
			fileManager.setVersion(version);
			fileManager.setMateriel(materiel);
			fileManager.setUploadUser(uploadUser);
			fileManager.setSpecialNum(specialNum);
			fileManagerDao.insertFileManager(fileManager);
			String parentFolderPath = "";
			if(parentStrCn!=null && !"".equals(parentStrCn)){
				 parentFolderPath = parentStrCn.replace(" -> ", "/");
			}
			//保存文件到服务器
			String folderPath = request.getSession().getServletContext().getRealPath("/"+parentFolderPath+"/"+fileName+"");
			File folderFile = new File(folderPath);
			fileUpload.transferTo(folderFile);
			jsonResult.setStatus(JSONResult.STATUS_SUCCESS);
			jsonResult.setMsg("上传文件成功!");
		}
		return jsonResult ;
	}
	 /**
	   * 删除文件夹或文件
	   * @param id
	   * @param request
	   * @return
	   */
	public @ResponseBody JSONResult<String> delete(Integer id,HttpServletRequest request){
		//找到其所属文件
		List<FileManager> list = fileManagerDao.selectFileManagerTree(id);
		//文件下的所有孩子
		List<FileManager> allChildrenList = getAllChildrenList(list ,new ArrayList<FileManager>());
		List<Integer> idList = new ArrayList<Integer>();
		for (FileManager fileManager : allChildrenList) {
			idList.add(fileManager.getId());
		}
		idList.add(id);
		FileManager filemanager = fileManagerDao.selectFileManagerById(id);
		String filePath = request.getSession().getServletContext().getRealPath("/"+filemanager.getParentStrCn().replace(" -> ", "/")+"/"+filemanager.getFileName());
		logger.info("删除文件夹目录："+filePath);
		System.out.println(filePath+"----------------");
		FileUtil.deleteFolder(filePath);
		//删除文件的二维码
		qrService.deleteQRimage(filemanager,request);
		fileManagerDao.deleteByList(idList);
		JSONResult<String> jsonResult = new JSONResult<String>();
		jsonResult.setStatus(JSONResult.STATUS_SUCCESS);
		jsonResult.setMsg("删除文件成功!");
		return jsonResult ;
	}
	/**
	 * 获取其底下所有子集
	 * @param sourceList
	 * @param resultList
	 * @return
	 */
	@Transactional(readOnly=true)
	private List<FileManager> getAllChildrenList(List<FileManager> sourceList ,List<FileManager> resultList){
		for (FileManager fileManager : sourceList) {
			resultList.add(fileManager);
			List<FileManager> children = fileManager.getChildren();
			if(children!=null && children.size()>0){
				getAllChildrenList(children,resultList);
			}
		}
		return resultList ;
	}
	/**
	  * 修改文件夹
	  * @param id
	  * @param fileName
	  * @param remarks
	  * @param parentId
	  * @param request
	  * @return
	  */
	 public JSONResult<String> updateFolder(Integer id,String fileName,String remarks,Integer parentId,HttpServletRequest request){
		FileManager fileManagerInDataBase = fileManagerDao.selectFileManagerByCondition(new FileManager(parentId,fileName,0));
		JSONResult<String> jsonResult = new JSONResult<String>();
		if(fileManagerInDataBase!=null && fileManagerInDataBase.getId()>1){
			jsonResult.setStatus(JSONResult.STATUS_FAILED);
			jsonResult.setMsg("该路径下已存在此文件夹,请更改文件夹名称,再修改！");
			return jsonResult;
		}
		FileManager oldFileManager = fileManagerDao.selectFileManagerById(id);
		FileManager parentFileManager = fileManagerDao.selectFileManagerById(parentId);
		String parentStrCn = parentFileManager.getParentStrCn()+" -> "+parentFileManager.getFileName();
		Integer level = parentFileManager.getLevel()+1;
		FileManager newFileManager = new FileManager(id,parentId,fileName,remarks,new Date(),level,parentStrCn);
		fileManagerDao.updateFileManagerFolderById(newFileManager); 
		List<FileManager> listFileManager = fileManagerDao.selectFileManagerTree(id);
		//updateFolderChildren(listFileManager,newFileManager);
		updateFolderChildren(listFileManager,parentStrCn ,level ,fileName);
		String oldFilePath = request.getSession().getServletContext().getRealPath("/"+oldFileManager.getParentStrCn().replace(" -> ", "/")+"/"+oldFileManager.getFileName());
		String newFilePath = request.getSession().getServletContext().getRealPath("/"+parentStrCn.replace(" -> ", "/")+"/"+fileName);
		FileUtil.moveFolder(oldFilePath, newFilePath);
		jsonResult.setStatus(JSONResult.STATUS_SUCCESS);
		jsonResult.setMsg("修改文件夹成功!");
		return jsonResult ;
	}
	 /**
	  * 修改文件夹
	  * @param id
	  * @param fileName
	  * @param oldFileName
	  * @param parentStrCn
	  * @param parentId
	  * @param remarks
	  * @return
	  */
	@Transactional(readOnly=true)
	private void updateFolderChildren(List<FileManager> childrenList,String parentStrCn ,Integer level,String fileName){
		if(childrenList!=null && childrenList.size()>0){
			for (FileManager children : childrenList) {
				Integer id = children.getId();
				Integer parentId = children.getParentId();
				//fileName = children.getFileName();
				String remarks = children.getRemarks();
				parentStrCn = parentStrCn+" -> "+ fileName;
				level = level+1;
				fileManagerDao.updateFileManagerFolderById(new FileManager(id, parentId, children.getFileName(), remarks, new Date(), level, parentStrCn));
				List<FileManager> listFileManager = fileManagerDao.selectFileManagerTree(id);
				updateFolderChildren(listFileManager,parentStrCn ,level ,fileName);
			}
		}
	}
	 /**
	  * 获取文件详情
	  * @param id
	  * @return
	  */
	 public FileManager selectFileManagerDetailById(Integer id){
		 return fileManagerDao.selectFileManagerDetailById(id);
	 }
	 /**
	  * 修改文件
	  * @param id
	  * @param fileName
	  * @param oldFileName
	  * @param parentStrCn
	  * @param parentId
	  * @param remarks
	  * @return
	  */
	 public JSONResult<String> updateFileManagerFile(FileManager fileManager,String oldFileName,Integer parentId ,HttpServletRequest request){
		JSONResult<String> jsonResult = new JSONResult<String>();
		FileManager fileManagerInDataBase = fileManagerDao.selectFileManagerByCondition(new FileManager(parentId,fileManager.getFileName(),0));
		if(fileManagerInDataBase!=null && fileManagerInDataBase.getId()>1){
			jsonResult.setStatus(JSONResult.STATUS_FAILED);
			jsonResult.setMsg("该路径下已存在此文件夹,请更改文件夹名称！");
		}else{
			 fileManagerDao.updateFileManagerFile(fileManager);
			 String oldFilePath = request.getSession().getServletContext().getRealPath("/"+fileManager.getParentStrCn().replace(" -> ", "/")+"/"+oldFileName+"");
			 String newFilePath = request.getSession().getServletContext().getRealPath("/"+fileManager.getParentStrCn().replace(" -> ", "/")+"/"+fileManager.getFileName()+"");
			 FileUtil.updateFileName(oldFilePath, newFilePath);
			 qrService.updateQRImage(oldFilePath,newFilePath);
			 jsonResult.setStatus(JSONResult.STATUS_SUCCESS);
			 jsonResult.setMsg("修改文件成功!");
		}
		return jsonResult ;
	 }
	
	
	/**
	 * 添加文件夹
	 * @param parentId
	 * @param parentStrCn
	 * @param level
	 * @param fileName
	 * @param request
	 * @return
	 */
	public JSONResult<String> insertFileFolder(Integer parentId,String parentStrCn,Integer level,String fileName,String remarks,HttpServletRequest request){
		JSONResult<String> jsonResult = new JSONResult<String>();
		FileManager fileManagerInDataBase = fileManagerDao.selectFileManagerByCondition(new FileManager(parentId,fileName,0));
		if(fileManagerInDataBase!=null && fileManagerInDataBase.getId()>1){
			jsonResult.setStatus(JSONResult.STATUS_FAILED);
			jsonResult.setMsg("该路径下已存在此文件夹,请更改文件夹名称！");
		}else{
			FileManager fileManager = new FileManager();
			fileManager.setParentId(parentId);
			fileManager.setParentStrCn(parentStrCn);
			fileManager.setLevel(level);
			fileManager.setFileName(fileName);
			fileManager.setRemarks(remarks);
			fileManager.setFileType(0);
			fileManager.setCreateDate(new Date());
			fileManager.setUpdateDate(new Date());
			fileManager.setDownloadCount(0);
			fileManagerDao.insertFileManager(fileManager);
			String parentFolderPath = "";
			if(parentStrCn!=null && !"".equals(parentStrCn)){
				 parentFolderPath = parentStrCn.replace(" -> ", "/");
			}
			//在服务器上新建文件
			String folderPath = request.getSession().getServletContext().getRealPath("/"+parentFolderPath+"/"+fileName+"");
			File folderFile = new File(folderPath);
			if (!folderFile.exists()) {
				folderFile.mkdirs();
			}
			
			qrService.creatQrImage(fileManager, request);
			jsonResult.setStatus(JSONResult.STATUS_SUCCESS);
			jsonResult.setMsg("新增文件夹成功。");
		}
		return jsonResult;
	}
	//创建二维码
	private void creatQRImage(int i,HttpServletRequest quest) {
			
			
	}
	//下载文件或者文件夹
	public void dowlondZip(HttpServletRequest request,FileManager filemanager, OutputStream out) {
			//更新下载次数
		Integer downloadCount =0;
		if(filemanager.getDownloadCount()==null){
			
		}else{
			downloadCount=filemanager.getDownloadCount();
		}
		filemanager.setDownloadCount(downloadCount+1);
		updataFileDowloandCount(filemanager);
			
			String filePath = request.getSession().getServletContext().getRealPath("/"+filemanager.getParentStrCn().replace(" -> ", "/")+"/"+filemanager.getFileName());
			System.out.println(filePath);
			String srcatchPath=request.getSession().getServletContext().getRealPath("/"+"srcatch");
			srcatchPath=srcatchPath+"/srcatchPath.zip";
			ZIPUtil.zip(filePath, srcatchPath);
			//将压缩文件放入临时文件夹
			dowlondsrcatchPathFile(srcatchPath,out);
				
	}
	//该文件的下载次数家底
	private void updataFileDowloandCount(FileManager filemanager) {
		fileManagerDao.updataFileDowloandCount(filemanager);
		
	}
	//下载zip
	private void dowlondsrcatchPathFile(String srcatchPath, OutputStream out) {
		try {
			File srcatchFile= new File(srcatchPath);
			System.out.print(srcatchFile);
			//找到该文件
			FileInputStream fint=new FileInputStream(srcatchFile);
			//缓冲区
			BufferedInputStream bis=new BufferedInputStream(fint);
			byte[] buf=new byte[1024];
			//读取
			int length=-1;
			while((length=bis.read(buf))!=-1){
				out.write(buf, 0, length);
			}
			//将临时文件删除
			out.close();
			//关闭流
			
			srcatchFile.delete();
		} catch (FileNotFoundException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}
	//下载普通文件
	public void dowlondFile(HttpServletRequest request,FileManager filemanager, ServletOutputStream outputStream) {
		try {
			filemanager.setDownloadCount(filemanager.getDownloadCount()+1);
			updataFileDowloandCount(filemanager);
			//获取当前文件
			String filePath = request.getSession().getServletContext().getRealPath("/"+filemanager.getParentStrCn().replace(" -> ", "/")+"/"+filemanager.getFileName());
			//读取
			File file=new File(filePath);
			FileInputStream fint=new FileInputStream(file);
			BufferedInputStream bis=new BufferedInputStream(fint);
			byte[] buf=new byte[1024];
			//读取
			int length=-1;
			while((length=bis.read(buf))!=-1){
				outputStream.write(buf, 0, length);
			}
			//关流
			outputStream.close();
		} catch (FileNotFoundException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}
	}
	/**
	 * 获取fileManager的树形结构
	 * @return
	 */
	@Transactional(readOnly=true)
	public TreeViewVo selectFileManagerTree(){
		TreeViewVo treeView = new TreeViewVo();
		FileManager fileManager = fileManagerDao.selectFileManagerFolderTree(0).get(0);
		treeView.setText(fileManager.getFileName());
		treeView.setIcon(fileManager.getFileType()==0?TreeViewVo.ICON_FOLDER:TreeViewVo.ICON_FILE);
		treeView.setNodes(new ArrayList<TreeViewVo>());
		treeView.setId(fileManager.getId());
		//treeView.setParentId(fileManager.getParentId());
		treeView.setParent_Id(fileManager.getParentId());
		treeView.setLevel(fileManager.getLevel());
		treeView.setParentStrCn(fileManager.getParentStrCn());
		treeView.setHref(TreeViewVo.FILE_MANAGER_HREF+fileManager.getId());
		getTreeViewByFileManager(treeView,fileManager);
		return treeView ;
	}
	/**
	 * 获取fileManager的树形结构
	 * @return
	 */
	@Transactional(readOnly=true)
	private TreeViewVo getTreeViewByFileManager(TreeViewVo treeView,FileManager fileManager){
		if(fileManager.getChildren()!=null && fileManager.getChildren().size()>0){
			List<FileManager> children = fileManager.getChildren();
			List<TreeViewVo> nodes = new ArrayList<TreeViewVo>();
			for (FileManager fileManager2 : children) {
				TreeViewVo treeView2 = new TreeViewVo();
				treeView2.setText(fileManager2.getFileName());
				treeView2.setIcon(fileManager2.getFileType()==0?TreeViewVo.ICON_FOLDER:TreeViewVo.ICON_FILE);
				treeView2.setId(fileManager2.getId());
				//treeView2.setParentId(fileManager2.getParentId());
				treeView2.setParent_Id(fileManager2.getParentId());
				treeView2.setLevel(fileManager2.getLevel());
				treeView2.setParentStrCn(fileManager2.getParentStrCn());
				treeView2.setHref(TreeViewVo.FILE_MANAGER_HREF+fileManager2.getId());
				nodes.add(treeView2);
				if(fileManager2.getChildren()!=null && fileManager2.getChildren().size()>0){
					getTreeViewByFileManager(treeView2, fileManager2);
				} 
			}
			treeView.setNodes(nodes);
		}
		return treeView ;
	}
	//文件查询
	public PageModel<FileManager> searchFilManagerFile(
			 String fileName ,String sysType ,String productName ,String productType,
			 String specialNum,String productModel,String uploadUser,String usageScenarios,
			 String documentType ,String version ,String materiel,
			Integer pageNo,Integer pageSize,HttpServletRequest request,ModelMap modelMap) {
		Map<String,Object> paramMap=new HashMap<String, Object>();
		
		if(fileName!=null && !"".equals(fileName)){
			paramMap.put("fileName", fileName);
		}
		if(sysType!=null && !"".equals(sysType)){
			paramMap.put("sysType", sysType);
		}
		if(productName!=null && !"".equals(productName)){
			paramMap.put("productName", productName);
		}
		if(productType!=null && !"".equals(productType)){
			paramMap.put("productType", productType);
		}
		if(specialNum!=null && !"".equals(specialNum)){
			paramMap.put("specialNum", specialNum);
		}
		if(productModel!=null && !"".equals(productModel)){
			paramMap.put("productModel",productModel);
		}
		if(uploadUser!=null && !"".equals(uploadUser)){
			paramMap.put("uploadUser", uploadUser);
		}
		if(usageScenarios!=null && !"".equals(usageScenarios)){
			paramMap.put("usageScenarios", usageScenarios);
		}
		if(documentType!=null && !"".equals(documentType)){
			paramMap.put("documentType", documentType);
		}
		if(version!=null && !"".equals(version)){
			paramMap.put("version", version);
		}
		if(materiel!=null && !"".equals(materiel)){
			paramMap.put("materiel", materiel);
		}
		paramMap.put("startRow", (pageNo-1)*pageSize);
		paramMap.put("pageSize", pageSize);
		List<FileManager> list = fileManagerDao.searchFilManagerFile(paramMap);
		//为其查找到的所有文件添加QR码图片路径
		for(FileManager filemanger:list){
			String parentFolderPath="";
			String parentStrCn=filemanger.getParentStrCn();
			if(parentStrCn!=null && !"".equals(parentStrCn)){
				 parentFolderPath = parentStrCn.replace(" -> ", "/");
			}
			String fileNameInDateBase=filemanger.getFileName();
			String folderPath="";
			String imagePath="";
			Image image=null;
			if(filemanger.getFileType()==1 ){
				//其为文件夹 文件夹有QR码
				//说明是文件文件则放在其相关父级目录下
				 folderPath = request.getSession().getServletContext().getRealPath("/"+parentFolderPath);
				 //去除后缀名
				 int indexOf = fileNameInDateBase.indexOf(".");
				 fileNameInDateBase=fileNameInDateBase.substring(0,indexOf);
				 imagePath=folderPath+fileNameInDateBase+".jpg";
			}else{
				//其为文件夹
				
				 folderPath =parentFolderPath+"/"+fileName+"";
				 imagePath=folderPath+"/"+fileName+".jpg";
				  image=new Image(imagePath);
			}
			filemanger.setImagePath(image);
		}
		
		int totalRecords = fileManagerDao.searchFilManagerFileCount(paramMap);
		PageModel<FileManager> pageModel = new PageModel<FileManager>();
		pageModel.setList(list);
		pageModel.setPageNo(pageNo);
		pageModel.setPageSize(pageSize);
		pageModel.setTotalRecords(totalRecords);
		return pageModel;
		
	}
}
